package com.example.myboradcastreceiver;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    One one;
    Two two;
    Three three;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        one = new One();
        IntentFilter filter = new IntentFilter();
        filter.addAction("nihaowoshixiaokeli");
        filter.setPriority(1000);
        registerReceiver(one, filter);
        two = new Two();
        filter.setPriority(700);
        registerReceiver(two, filter);
        three = new Three();
        filter.setPriority(800);
        registerReceiver(three, filter);
        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendOrderedBroadcast(new Intent("nihaowoshixiaokeli"), null);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(one);
        unregisterReceiver(two);
        unregisterReceiver(three);
    }
}